function moveMe(steps) {
	if (selectedBlock == 0) {
		alert('Nothing selected');
		return false;
	}
	if ( steps != 1 ) {
		eval('colIdx=b' + selectedBlock+ '.getCurrentColumn()');
		if (colIdx == 0 ) {
			alert('You can move only if you get a 1');
			return true;
		}
	}
	eval( 'b' + selectedBlock+ '.goBy(' + steps + ')');
	return true;
}

function generateThrow() {
	hasGameStarted = 1;
	t = Math.floor(Math.random()*16);
	$('.blSelected').removeClass('blSelected');
	selectedBlock = 0;
	switch (t) {
		case 0: 
		case 1: 
		case 2: 
		case 3: addThrow(1); generateThrow(); break;
		case 4: 
		case 5:  
		case 6: 
		case 7: 
		case 8: ;
		case 9: addThrow(2); break;
		case 10:  
		case 11: 
		case 12: 
		case 13: addThrow(3); break;
		case 14: addThrow(4); generateThrow(); break;
		case 15: addThrow(8); generateThrow(); break;
	}
	
}

function addThrow(i) {
	//$('#divThrows').append( ' <a href="#" onclick="moveMe(' + i + ');$(this).hide()">' + i + '</a> ');
	$('#divThrows').append( ' <a href="#" onclick="processThrow(' + i + ',this)">' + i + '</a> ');
}

function processThrow(i,obj) {
	if (moveMe(i)) {
		$(obj).hide();
	}
}

function toggleMenu() {
	if ($("#helper").is(':visible') ) {		
		$("#iHelpMenu").empty();
		$("#iHelpMenu").append('Show help');
	} else {
		$("#iHelpMenu").empty();
		$("#iHelpMenu").append('Hide help');
	}

	 $("#helper").animate({height:'toggle'},960);
}

function choosePlayers(p) {
	if (hasGameStarted == 1) {
		alert('The game has already started. Refresh to start new game');
		return false;
	}
	$('.spBlock').hide();
	
	if ( p == 4 ) {
		isTeamMode = 1;
	} else {
		isTeamMode = 0;
	}
	
	switch(p) {
		case '2':	showPlayer(1);showPlayer(2);
					break;
		case '3':	showPlayer(1);showPlayer(2);showPlayer(4);
					break;
		case '4':	showPlayer(1);showPlayer(2);showPlayer(3);showPlayer(4);
					break;
	}
}

function showPlayer(p) {
	for (i=1; i<5; i++ ) {
		$('#block'+p+i).show();
	}
}

function changeMode(m) {
	if (m==0) {
		isManualMode = 0;
	} else {
		isManualMode = 1;
	}
}